﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace CardClass
{
    public class CardControlChar : Control
    {
        Rectangle border;
        SolidColorBrush brush_border = new SolidColorBrush();
        TextBlock character;
        TextBlock skill;
        TextBlock HP;
        Image logo;
        FrameworkElement implementationRoot;

        RotateTransform rotate;
        TranslateTransform translate;

        public CardControlChar()
        {
            System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("CardClass.CardControlChar.xaml");
            implementationRoot = this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());
            
            border = implementationRoot.FindName("border") as Rectangle; 
            character = implementationRoot.FindName("character") as TextBlock;
            skill = implementationRoot.FindName("skill") as TextBlock;
            HP = implementationRoot.FindName("HP") as TextBlock;
            logo = implementationRoot.FindName("logo") as Image;

            rotate = implementationRoot.FindName("Rotate") as RotateTransform;
            translate = implementationRoot.FindName("Translate") as TranslateTransform;
            // Default layout
            this.Width = 90;
            this.Height = 120;

            rotate.CenterX = this.Width / 2;
            rotate.CenterY = this.Height / 2;

            this.MouseEnter += new MouseEventHandler(CardControl_MouseEnter);
            this.MouseLeave += new EventHandler(CardControl_MouseLeave);
            this.Cursor = Cursors.Hand;
            //this.MouseLeftButtonDown += new MouseEventHandler(CardControl_MouseLeftButtonDown);
            //this.MouseLeftButtonUp += new MouseEventHandler(CardControl_MouseLeftButtonUp);
            //this.MouseMove += new MouseEventHandler(CardControl_MouseMove);
        }

        void CardControl_MouseLeave(object sender, EventArgs e)
        {
            BorderColor = Color.FromRgb(0, 0, 0);
        }
        void CardControl_MouseEnter(object sender, MouseEventArgs e)
        {
            BorderColor = Color.FromRgb(0, 0, 255);
        }

        public virtual new double Height
        {
            get { return implementationRoot.Height; }
            set { 
                implementationRoot.Height = value;
                border.Height = value;
            }
        }
        public virtual new double Width
        {
            get { return implementationRoot.Width; }
            set {
                implementationRoot.Width = value;
                border.Width = value;
            }
        }
        public String CharText
        {
            get { return character.Text; }
            set { character.Text = value; }
        }
        public String SkillText
        {
            get { return skill.Text; }
            set { skill.Text = value; }
        }
        public String HPText
        {
            get { return HP.Text; }
            set { HP.Text = value; }
        }
        public Color BorderColor
        {
            get { return brush_border.Color; }
            set 
            {
                brush_border.Color = value;
                border.Stroke = brush_border;
            }
        }
        public void SetURI(DependencyObject downloader, string path)
        {
            logo.SetSource(downloader, path);
        }
        public double Left
        {
            get { return translate.X; }
            set { translate.X = value; }
        }
        public double Top
        {
            get { return translate.Y; }
            set { translate.Y = value; }
        }
        public double Angle
        {
            get { return rotate.Angle; }
            set { rotate.Angle = value; }
        }

    }
}
